package com.winner.strategy_pattern.pay;

import com.google.common.collect.Maps;
import org.springframework.util.StringUtils;

import java.util.Map;

public class PaymentFactory {
    private static Map<String, PaymentStrategy> strategyMap = Maps.newHashMap();

    public static PaymentStrategy getInvokeStrategy(String name) {
        return strategyMap.get(name);
    }

    // 调用此方法初始化到静态 strategyMap中
    // 开闭原则 对新增开放, 对修改关闭
    public static void register(String name, PaymentStrategy paymentStrategy) {
        if (StringUtils.isEmpty(name) || null == paymentStrategy) {
            return;
        }
        strategyMap.put(name, paymentStrategy);
    }
}
